package com.powernode.config;

import com.powernode.constant.QueueConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 内容:
 * 作者: cy
 */
@Configuration
public class OrderQueueConfig {


    @Bean
    public Queue orderMsQueue() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-message-ttl", 120 * 1000);
        args.put("x-dead-letter-exchange", QueueConstant.ORDER_DEAD_EX);
        args.put("x-dead-letter-routing-key", QueueConstant.ORDER_DEAD_KEY);
        return new Queue(QueueConstant.ORDER_MS_QUEUE, true, false, false, args);
    }

    @Bean
    public Queue orderDeadQueue() {
        return new Queue(QueueConstant.ORDER_DEAD_QUEUE);
    }


    @Bean
    public DirectExchange orderDeadEx() {
        return new DirectExchange(QueueConstant.ORDER_DEAD_EX);
    }

    @Bean
    public Binding orderDeadBind() {
        return BindingBuilder.bind(orderDeadQueue()).to(orderDeadEx()).with(QueueConstant.ORDER_DEAD_KEY);
    }

    @Bean
    public Queue prodEsChangeQueue() {
        return new Queue(QueueConstant.PROD_ES_CHANGE_QUEUE);
    }


}
